www.gusucode.com > FavShop网店系统源码程序 > FavShop网店系统 1.0/upload/app/webroot/js/product.js

    function editProduct(id){
	var name			= $('ProductName').value;
	var introduce		= tinyMCE.getContent();
	var category_id		= $('hdCategoryId').value;
	var brand_id		= $('ProductBrandId').value;
	var price			= $('ProductPrice').value;
	var discount		= $('ProductDiscountPrice').value;
	
	if(name==''){
		alert('请填写商品名称!');
		$('ProductName').focus();
		return;
	}
	
	if(category_id==0){
		alert('请选择商品分类!');
		return;
	}
	
	if(!isPrice(price,false)){
		alert('请填写正确的商品价格!');
		$('ProductPrice').focus();
		return;
	}
	
	if(!isPrice(discount,false)){
		alert('请填写正确的折扣价格!');
		$('ProductDiscountPrice').focus();
		return;
	}
	
	if(introduce==''){
		alert('请填写商品简介!');
		//$('BrandIntroduce').focus();
		return;
	}
	
	if(brand_id=='')
		brand_id	= 0;
	
	var url;
	if(id!=0){
		new Ajax.Updater("divResult", AppRoot+"/products/edit",{
			method: 'post', 
			asynchronous: true,
			evalScripts:true,		parameters:{'data[Product][name]':name,'data[Product][introduce]':introduce,'data[Product][category_id]':category_id,'data[Product][brand_id]':brand_id,'data[Product][price]':price,'data[Product][discount_price]':discount,'data[Product][id]':id,'rnd':Math.random()},
			onComplete:function(r){
			}
		});
	}else{
		new Ajax.Updater("divResult", AppRoot+"/products/add",{
		method: 'post', 
		asynchronous: true,
		evalScripts:true,		parameters:{'data[Product][name]':name,'data[Product][introduce]':introduce,'data[Product][category_id]':category_id,'data[Product][brand_id]':brand_id,'data[Product][price]':price,'data[Product][discount_price]':discount,'rnd':Math.random()},
		onComplete:function(r){
		}
	});
	}
}


function deleteImage(id,i,f){
	new Ajax.Updater("divResult",AppRoot+'/products/del', {
			asynchronous:true, 
			evalScripts:true, 
			parameters:{'Id':id,'Image':f}, 
			requestHeaders:['X-Update', 'divCategory'],
			onComplete:function(request, json) {
				$('trImages').removeChild($('td'+i));
			}
		}
		);
}

function addFav(id){
	new Ajax.Request(AppRoot+'/products/fav/'+id, {
			asynchronous:true, 
			evalScripts:true, 
			parameters:{}, 
			onComplete:function(request, json) {
				alert(request.responseText);
			}
		}
	);
}

function vote(id){
	new Ajax.Request(AppRoot+'/products/vote/'+id, {
			asynchronous:true, 
			evalScripts:true, 
			parameters:{'Id':id}, 
			requestHeaders:['X-JSON', 'divResult'],
			onComplete:function(request, json) {
				var json = request.responseText.evalJSON();
				
				var msg		= '推荐失败,可能你已经推荐过该商品!';
				if(json.num!=0){
					$("spSuggset").innerHTML	= json.num;
					msg		= '推荐成功!';
				}
				alert(msg);
			}
		}
	);
}

function setSpecial(id){
	new Ajax.Request(AppRoot+'/products/special/'+id, {
			asynchronous:true, 
			evalScripts:true, 
			parameters:{}, 
			requestHeaders:['X-JSON'],
			onComplete:function(request, json){
				alert(request.responseText);
				document.location.reload();
			}
		}
	);
}

function doOperation(op){
	var n	= checkNums('checkbox[]');
	if(n==0){
		alert('请选择要操作的商品!');
		return;
	}
	document.getElementById('hdOperation').value	= op;
	document.getElementById('frmSubmit').submit();
}